local zhiheng = fk.CreateSkill {
  name = "lvshi__zhiheng",
  tags = {"Phase"}
}

Fk:loadTranslationTable{
  ["lvshi__zhiheng"] = "制衡",
  ["#lvshi__zhiheng_trigger"] = "你可以弃置至少一张牌，摸等量的牌",
  [":lvshi__zhiheng"] = "阶段技，你可弃置至少一张牌，摸等量的牌，若你弃置了一个区域内所有的牌，你多摸一张牌；否则你可少摸一张牌并重置此技能。",
  ["#lvshi__zhiheng"] = "你可以少摸一张牌，重置制衡",

  ["$lvshi__zhiheng1"] = "多思多谋，筹谋长远。",
  ["$lvshi__zhiheng2"] = "不偏不倚，制而取衡。",
  ["$lvshi__zhiheng3"] = "息兵，等待时机，再战不迟。",
}

zhiheng:addEffect("active", {
  anim_type = "drawcard",
  prompt = "#lvshi__zhiheng_trigger",
  max_phase_use_time = 1,
  target_num = 0,
  min_card_num = 1,
  card_filter = function(self, player, to_select)
    return not player:prohibitDiscard(to_select)
  end,
  on_use = function(self, room, effect)
    local from = effect.from
    local more = 0
    if (table.every(from:getCardIds("h"), function (id) return table.contains(effect.cards, id) end) and #from:getCardIds("h") > 0)
    or (table.every(from:getCardIds("e"), function (id) return table.contains(effect.cards, id) end) and #from:getCardIds("e") > 0) then
      more = more + 1
    end
    room:throwCard(effect.cards, zhiheng.name, from, from)
    local n = #effect.cards + more
    if more == 0 and room:askToSkillInvoke(from, {skill_name = zhiheng.name, prompt = "#lvshi__zhiheng"}) then
      n = n - 1
      from:setSkillUseHistory(zhiheng.name, 0, Player.HistoryPhase)
    end
    room:drawCards(from, n, zhiheng.name)
  end,
})

return zhiheng